﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using Utilities;

namespace Tokenization
{
    public class TokenRules
    {
        public string Name { get; set; }
        public List<Token> Tokens { get; set; }
        public TokenRules() { Tokens = new List<Token>(); this.Name = "Default"; }
        public TokenRules(string name) { Tokens = new List<Token>(); this.Name = name; }
        public void AddToken(string name,bool type, string p0, string p1, string p2)
        {
            Token t = new Token();
            t.Name = name;
            t.Type = type;
            t.Pattern0 = p0;
            t.Pattern1 = p1;
            t.Pattern2 = p2;
            Tokens.Add(t);
            System.Diagnostics.Debug.WriteLine("Token with Name:" + name + " added.");
        }
        public static void serialize(string path,TokenRules tr)
        {
            System.Diagnostics.Debug.WriteLine("Serializing Rules...");
            Serialization.serialize(path,tr,Serialization.FormatType.XML);
            System.Diagnostics.Debug.WriteLine("OK");
        }
        public static TokenRules deserialize(string path)
        {
            System.Diagnostics.Debug.WriteLine("Deserializing Rules...");
            TokenRules tr = Serialization.deserialize<TokenRules>(path,Serialization.FormatType.XML);
            System.Diagnostics.Debug.WriteLine("OK");
            return tr;
        }
    }
    public class Token 
    {
        public string Name { get; set; }
        public bool Type { get; set; }
        public string Pattern0 { get; set; }
        public string Pattern1 { get; set; }
        public string Pattern2 { get; set; }
        [XmlIgnore]
        public Rule Rule { get { return new Rule(Pattern0,Pattern1,Pattern2);} }
    }
}
